package com.zhxin.nettylab.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @ClassName HttpServerInitializer
 * @Description //HttpServerInitializer
 * @Author singleZhang
 * @Email 405780096@qq.com
 * @Date 2021/2/25 0025 上午 11:44
 **/
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline ch = socketChannel.pipeline();
        //HttpServerCodec可以被HttpResponseEncoder、HttpRequestDecoder两个替代
        ch.addLast("httpServerCodec",new HttpServerCodec())
                .addLast("aggregator", new HttpObjectAggregator(65536))
                .addLast("httpServerHandler",new HttpServerHandler());
    }
}
